//# sourceURL=http://uMapApp/Module/SettingsModule
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "uEarth/uEarth",
    "./Module"
    , "../UI/Panel/FloatPanel"
    , "../UI/Panel/PanelBlock/PanelBlock"
    , "../UI/Panel/Item/FormItem"
    , "../UI/Checkbox"
], function (
    mhjs,
    uMap,
    uEarth,
    Module
    , FloatPanel
    , PanelBlock
    , FormItem
    , Checkbox
) {

    function SettingsModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "系统设置";
        _this.icon = _this.app.icons.setting;

        _this.panels = [];

        _this.setting = _this.app.earth.setting;

        _this.settingsPanel = new FloatPanel({"class": "rightPanel SettingsModule newPanel"});
        _this.settingsPanel.settingsBlock = new PanelBlock();

        _this.settingsPanel.settingsBlock.earthForm = new FormItem({
            title   : "地球",
            subtitle: "设置三维地球可视效果",
            "class" : "checkboxItem"
        });
        _this.settingsPanel.settingsBlock.environmentForm = new FormItem({
            title   : "环境",
            subtitle: "设置渲染效果参数",
            "class" : "switchItem"
        });

        _this.settingsPanel.settingsBlock.debugForm = new FormItem({
            title   : "调试",
            subtitle: "开启调试",
            "class" : "switchItem"
        });

        _this.settingsPanel.settingsBlock.ui.wrap
            .append(_this.settingsPanel.settingsBlock.earthForm)
            .append(_this.settingsPanel.settingsBlock.environmentForm)
            .append(_this.settingsPanel.settingsBlock.debugForm)
        ;

        _this.isImageryShow = new Checkbox();
        _this.isImageryShow.label = "影像";
        _this.isImageryShow.bind(_this.setting, "isImageryShow");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isImageryShow);

        _this.isTerrainShow = new Checkbox();
        _this.isTerrainShow.label = "地形";
        _this.isTerrainShow.bind(_this.setting, "isTerrainShow");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isTerrainShow);

        _this.isShowSun = new Checkbox();
        _this.isShowSun.label = "太阳";
        _this.isShowSun.bind(_this.setting, "isShowSun");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isShowSun);

        _this.isShowSky = new Checkbox();
        _this.isShowSky.label = "星空";
        _this.isShowSky.bind(_this.setting, "isShowSky");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isShowSky);

        _this.isShowAtmosphere = new Checkbox();
        _this.isShowAtmosphere.label = "大气层";
        _this.isShowAtmosphere.bind(_this.setting, "isShowAtmosphere");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isShowAtmosphere);

        _this.isShowGridImagery = new Checkbox();
        _this.isShowGridImagery.label = "经纬网格";
        _this.isShowGridImagery.bind(_this.setting, "isShowGridImagery");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isShowGridImagery);

        _this.isShowCompass = new Checkbox();
        _this.isShowCompass.label = "指南针";
        _this.isShowCompass.bind(_this.setting, "isShowCompass");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isShowCompass);

        _this.isShowDistanceLegend = new Checkbox();
        _this.isShowDistanceLegend.label = "比例尺";
        _this.isShowDistanceLegend.bind(_this.setting, "isShowDistanceLegend");
        _this.settingsPanel.settingsBlock.earthForm.add(_this.isShowDistanceLegend);

        _this.isHighResolution = new Checkbox({
            "class": "switch"
        });
        _this.isHighResolution.label = "4K渲染模式";
        _this.isHighResolution.bind(_this.setting, "isHighResolution");
        _this.settingsPanel.settingsBlock.environmentForm.add(_this.isHighResolution);

        _this.isOpenFxaa = new Checkbox({
            "class": "switch"
        });
        _this.isOpenFxaa.label = "全局抗锯齿";
        _this.isOpenFxaa.bind(_this.setting, "isOpenFxaa");
        _this.settingsPanel.settingsBlock.environmentForm.add(_this.isOpenFxaa);

        _this.isShowShadow = new Checkbox({
            "class": "switch"
        });
        _this.isShowShadow.label = "实时光影渲染";
        _this.isShowShadow.bind(_this.setting, "isShowShadow");
        _this.settingsPanel.settingsBlock.environmentForm.add(_this.isShowShadow);

        _this.isFixedTime = new Checkbox({
            "class": "switch"
        });
        _this.isFixedTime.label = "锁定白天光照";
        _this.isFixedTime.bind(_this.setting, "isFixedTime");
        _this.settingsPanel.settingsBlock.environmentForm.add(_this.isFixedTime);

        _this.isShowDebug = new Checkbox({
            "class": "switch"
        });
        _this.isShowDebug.label = "开启调试";
        _this.isShowDebug.on("change", function (checkbox) {
            _this.app.debug.isDebug = checkbox.isChecked;
        });
        _this.settingsPanel.settingsBlock.debugForm.add(_this.isShowDebug);

        _this.isShowDebugTransForm = new Checkbox({
            "class": "switch"
        });
        _this.isShowDebugTransForm.label = "开启模型位置调整";
        _this.isShowDebugTransForm.on("change", function (checkbox) {
            _this.app.debug.debugTransform = checkbox.isChecked;
        });
        _this.settingsPanel.settingsBlock.debugForm.add(_this.isShowDebugTransForm);


        _this.isShowDebugFeature = new Checkbox({
            "class": "switch"
        });
        _this.isShowDebugTransForm.label = "开启模型构件信息";
        _this.isShowDebugFeature.on("change", function (checkbox) {
            _this.app.debug.debugFeature = checkbox.isChecked;
        });
        _this.settingsPanel.settingsBlock.debugForm.add(_this.isShowDebugFeature);

        _this.settingsPanel.append(_this.settingsPanel.settingsBlock);
        _this.settingsPanel.settingsBlock.title = _this.title;

        _this.panels.push(_this.settingsPanel);

        _this.app.ui.layout.right.append(_this.settingsPanel);

    }

    var _class = SettingsModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "open"  : {
            value: function () {
                var _this = this;
                _this.settingsPanel.open(false);
                _this.isOpened = true;
            }
        },
        "close" : {
            value: function () {
                var _this = this;
                _this.settingsPanel.close(false);
                _this.isOpened = false;
            }
        },
        "toggle": {
            value: function () {
                var _this = this;
                if (_this.isOpened) {
                    _this.close();
                } else {
                    _this.open();
                }
            }
        }
    });

    return _class;

});